/*

Script: Showcase.js
  Showcase - A mootools based image gallery

Version: 0.1
Mootools: 1.1

Author
  Corey Wilson, <http://2catdesigns.com>
  
*/

window.addEvent('domready', function() {
  sc = new Showcase();
});

Element.extend({
  hide: function(){
    this.setStyle("display", "none");
  },
  show: function(){
    this.setStyle("display", "block");
  }
});

var Showcase = new Class({

  pane_current : 0,

  initialize: function() {
    this.pane_count = $ES('.showcase-pane').length - 1;
    this.pane_width = $ES('.showcase-pane')[0].getStyle('width').toInt();

    ['showcase-prev', 'showcase-next'].each(function(button) {
      this.init_button(button);
    },this);

    $('showcase-prev').addEvent('click', this.move.pass(-1, this));
    $('showcase-next').addEvent('click', this.move.pass(1, this));
    
    $('showcase-prev').hide();
  },

  move: function(direction) {
    this.move_to(this.pane_current + direction);
  },

  move_to: function(pane_index) {
    if(typeof this.slide != 'undefined') this.slide.stop();    
    this.slide = $('showcase-window').effect('left', {duration: 850, wait:false, transition: Fx.Transitions.Expo.easeOut}); 
    this.slide.start(pane_index * this.pane_width * -1);

    this.pane_current = pane_index;

    if (pane_index == 0) { 
      $('showcase-prev').hide(); 
      $('showcase-next').show(); 
    
    } else if (pane_index == this.pane_count) { 
      $('showcase-prev').show(); 
      $('showcase-next').hide(); 
    
    } else { 
      $('showcase-prev').show(); 
      $('showcase-next').show(); 
    }
  },

  init_button: function(button) {
    $(button).setOpacity(0.4);
    $(button).onmouseover = this.toggle_button.pass([button, 0.9], this);
    $(button).onmouseout = this.toggle_button.pass([button, 0.4], this);
  },

  toggle_button: function(id, value) {
    if(typeof this.fade != 'undefined') this.fade.stop();
    this.fade = new Fx.Style($(id), 'opacity').start(value);
  }

});
